<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    var arr = [,1,3,4,6,10];
    arr.sort((a,b)=>{
        // console.log('a-3:'+Math.abs(a-3).toString());
        // console.log('b-3:'+Math.abs(b-3).toString());
        console.log("a:"+a);
        console.log("b:"+b);
        return Math.abs(a-3)-Math.abs(b-3);
    })
    console.log(arr)
</script>
</body>
</html>